/*package com.bsoft.exchange.config.ds;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import com.alibaba.druid.pool.xa.DruidXADataSource;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.microsoft.sqlserver.jdbc.SQLServerXADataSource;

import oracle.jdbc.xa.client.OracleXADataSource;


@Configuration
@MapperScan(basePackages = "com.bsoft.exchange.dao.portal", sqlSessionFactoryRef = "portalSqlSessionFactory")
public class MyBatisConfig3 {

	// dao xml路径
	static final String MAPPER_LOCATION = "classpath:mapper/portal/sqlserver/*.xml";
	static final String MAPPER_LOCATION_ORACLE = "classpath:mapper/portal/oracle/*.xml";

	@Value("${datasource.portal.dbType}")
	private String dbType;

	// 配置数据源
	
	@Bean(name = "portalDataSource")
	public DataSource testDataSource(DBConfigPortal testConfig) throws SQLException {

		AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
		
		DruidXADataSource druidXADataSource = new DruidXADataSource(); 
		druidXADataSource.setUrl(testConfig.getUrl());
		druidXADataSource.setPassword(testConfig.getPassword());
		druidXADataSource.setUsername(testConfig.getUsername());
		xaDataSource.setXaDataSource(druidXADataSource);

		if (this.dbType.equals("1")) {
			SQLServerXADataSource sqlServerXADataSource = new SQLServerXADataSource();
			//		MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
			sqlServerXADataSource.setURL(testConfig.getUrl());
			//		sqlServerXADataSource.setPinGlobalTxToPhysicalConnection(true);
			sqlServerXADataSource.setPassword(testConfig.getPassword());
			sqlServerXADataSource.setUser(testConfig.getUsername());
			//		sqlServerXADataSource.setPinGlobalTxToPhysicalConnection(true);

			xaDataSource.setXaDataSource(sqlServerXADataSource);
			
		} else {
			OracleXADataSource oracleXADataSource = new  OracleXADataSource();
			oracleXADataSource.setURL(testConfig.getUrl());
//			oracleXADataSource.setPinGlobalTxToPhysicalConnection(true);
			oracleXADataSource.setPassword(testConfig.getPassword());
			oracleXADataSource.setUser(testConfig.getUsername());
//			oracleXADataSource.setPinGlobalTxToPhysicalConnection(true);
			xaDataSource.setXaDataSource(oracleXADataSource);
		}
		xaDataSource.setUniqueResourceName("portalDataSource");
		
		xaDataSource.setMinPoolSize(testConfig.getMinPoolSize());
		xaDataSource.setMaxPoolSize(testConfig.getMaxPoolSize());
		xaDataSource.setMaxLifetime(testConfig.getMaxLifetime());
		xaDataSource.setBorrowConnectionTimeout(testConfig.getBorrowConnectionTimeout());
		xaDataSource.setLoginTimeout(testConfig.getLoginTimeout());
		xaDataSource.setMaintenanceInterval(testConfig.getMaintenanceInterval());
		xaDataSource.setMaxIdleTime(testConfig.getMaxIdleTime());
		xaDataSource.setTestQuery(testConfig.getTestQuery());
		return xaDataSource;
	}

	@Bean(name = "portalSqlSessionFactory")
	
	public SqlSessionFactory testSqlSessionFactory(@Qualifier("portalDataSource") DataSource dataSource) throws Exception {
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		bean.setDataSource(dataSource);

		if (this.dbType.equals("1")) { // sqlserver
			bean.setMapperLocations(
					new PathMatchingResourcePatternResolver().getResources(MyBatisConfig3.MAPPER_LOCATION));
		} else { // oracle
			bean.setMapperLocations(
					new PathMatchingResourcePatternResolver().getResources(MyBatisConfig3.MAPPER_LOCATION_ORACLE));
		}
		return bean.getObject();
	}

	@Bean(name = "portalSqlSessionTemplate")
	
	public SqlSessionTemplate testSqlSessionTemplate(
			@Qualifier("portalSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
		return new SqlSessionTemplate(sqlSessionFactory);
	}
}*/